<?php if (!defined('THINK_PATH')) exit();?><!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>上海泛软科技有限公司-后台登陆</title>
<meta name="robots" content="nofollow" />
<meta name=”viewport” content=”width=device-width, initial-scale=1, maximum-scale=1″>
<link href="/Public/Css/admin-style.css" rel="stylesheet" type="text/css" />
<link href="/Public/Css/bootstrap.css" rel="stylesheet" type="text/css" />
<link href="/Public/Css/bootstrap.min.css" rel="stylesheet" type="text/css" />


<script language="javascript" type="text/javascript" src="/Public/Js/jquery.js"></script>
<script language="javascript" type="text/javascript" src="/Public/Js/admin-common.js"></script>
<script language="javascript" type="text/javascript" src="/Public/Js/bootstrap.min.js"></script>
<!--<script language="javascript" type="text/javascript" src="/Public/Js/bootstrap.js"></script> -->
<script language="javascript" type="text/javascript" src="/Public/Js/rock_customer_list.js"></script>
<script language="javascript" type="text/javascript" src="/Public/Js/demo.js"></script>
<script language="javascript" type="text/javascript" src="/Public/Js/blob.js"></script>
<script language="javascript" type="text/javascript" src="/Public/Js/FileSaver.min.js"></script>
<script language="javascript" type="text/javascript" src="/Public/Js/jquery.base64.js"></script>
<script language="javascript" type="text/javascript" src="/Public/Js/jquery-1.10.2.min.js"></script>
<script language="javascript" type="text/javascript" src="/Public/Js/tableExport.js"></script>
<script language="javascript" type="text/javascript" src="/Public/Js/xlsx.core.min.js"></script>
</head>

<body>

<style>
  #hedaer{
     background:#B9D3EE;
	 padding-left:0px;
	 background-color:rgba(185,211,238,0.15);
	 width:100%;
	 height:110px;
	 border-bottom: 1px solid #ccc;
	 overflow:hidden ;
	 padding:5px;
  }
  .select_Sty{
     float:left;
  }
   .select_Sty select {
   width: 150px;
   padding: 1px;
   font-size: 14px;
   border: 1px solid #ccc;
   height: 20px;
   margin-right:20px;
   border-radius:5px
}
.select_Sty input{
   width: 150px;
   padding: 1px;
   font-size: 12px;
   border: 1px solid #ccc;
   height: 20px;
   margin-right:20px;
   border-radius:5px
}
 #content #boder{
    padding-left:10px;
	padding-right:10px;
   
 }
 body{
   background-color:rgba(232,232,232,0.25);
 }
 h4{
    font-size: 14px;
	margin-bottom:0px;
 }
 h5{
   font-size: 10px;
 }
</style>
<!-- <form enctype="multipart/form-data" class="table-form" name="form1" method="post" action="<?php echo U('equipment_search_Management');?>">
 --><div id="background"> 
 
 <div id="hedaer">
   <h4 id="fileName">设备管理</h4>
   <div class="select_Sty">
   <h5>省份:</h5>
    <select name="sheng" id="sheng">
	<option selected="selected" value ="请选择">请选择</option>
	<?php if(is_array($province)): $i = 0; $__LIST__ = $province;if( count($__LIST__)==0 ) : echo "" ;else: foreach($__LIST__ as $key=>$province): $mod = ($i % 2 );++$i;?><option value ='<?php echo ($province["pro"]); ?>'><?php echo ($province["pro"]); ?></option><?php endforeach; endif; else: echo "" ;endif; ?>
    </select>
   </div>	
    <div class="select_Sty">
     <h5>区、县:</h5>
    <select name="qu" id="qu">
	<option selected="selected" value ="请选择">请选择</option>
	<?php if(is_array($city)): $i = 0; $__LIST__ = $city;if( count($__LIST__)==0 ) : echo "" ;else: foreach($__LIST__ as $key=>$city): $mod = ($i % 2 );++$i;?><option value ='<?php echo ($city["city"]); ?>'><?php echo ($city["city"]); ?></option><?php endforeach; endif; else: echo "" ;endif; ?>
    </select>
   </div>
   <div class="select_Sty">
     <h5>医院:</h5>
    <select name="yiyuan" id="yiyuan">
	 <option selected="selected" value ="请选择">请选择</option>
	<?php if(is_array($hos)): $i = 0; $__LIST__ = $hos;if( count($__LIST__)==0 ) : echo "" ;else: foreach($__LIST__ as $key=>$hos): $mod = ($i % 2 );++$i;?><option value ='<?php echo ($hos["name"]); ?>'><?php echo ($hos["name"]); ?></option><?php endforeach; endif; else: echo "" ;endif; ?>
    </select>
   </div>
   <div class="select_Sty">
     <h5>设备编号:</h5>
    <!-- <select name="bianhao" id="bianhao">
	  <option selected="selected" value ="请选择">请选择</option>
	  <?php if(is_array($device_num)): $i = 0; $__LIST__ = $device_num;if( count($__LIST__)==0 ) : echo "" ;else: foreach($__LIST__ as $key=>$device_num): $mod = ($i % 2 );++$i;?><option value ='<?php echo ($device_num["num"]); ?>'><?php echo ($device_num["num"]); ?></option><?php endforeach; endif; else: echo "" ;endif; ?>
    </select> -->
	<input type="type" class="bianhao"  name="bianhao" id="bianhao" placeholder="请输入设备编号"></input>
   
   </div>
   <div class="select_Sty">
     <h5>类型:</h5>
    <select name="leixing" id="leixing">
	 <option selected="selected" value ="请选择">请选择</option>
	  <?php if(is_array($device_style)): $i = 0; $__LIST__ = $device_style;if( count($__LIST__)==0 ) : echo "" ;else: foreach($__LIST__ as $key=>$device_style): $mod = ($i % 2 );++$i;?><option value ='<?php echo ($device_style["style"]); ?>'><?php echo ($device_style["style"]); ?></option><?php endforeach; endif; else: echo "" ;endif; ?>
    </select>
   </div>
   <div class="select_Sty">
     <h5>状态:</h5>
    <select name="static" id="static">
	  <option selected="selected" value ="请选择">请选择</option>
	  <?php if(is_array($device_status)): $i = 0; $__LIST__ = $device_status;if( count($__LIST__)==0 ) : echo "" ;else: foreach($__LIST__ as $key=>$device_status): $mod = ($i % 2 );++$i;?><option value ='<?php echo ($device_status["sta"]); ?>'><?php echo ($device_status["sta"]); ?></option><?php endforeach; endif; else: echo "" ;endif; ?>
    </select>
   </div>
   <div id="search" style="margin-left:60px;margin-top:30px">
    <button type="submit"  class="btn btn-primary btn-sm search">查询</button>
   </div>
 </div>   
<!--  </form> -->
 <div id="content">
   <div id="boder">
   <div style="100%;">
      <div id="items" style="width:80%;float:left;"> 
        <p><span id="count"></span></p> 
      </div>
	  <div style="width:20%;float:left;text-align:center">
		 <ul style="float:left;font-weight:bold">
		   <li style="float:left;margin:2px"><a href="#" id="modify" data-toggle="modal" data-target="#myModal">编辑</a></li>
		   <li style="float:left;margin:2px"><a href="<?php echo U('equipment_Management_Add');?>" >增加</a></li>
		   <li style="float:left;margin:2px"><a onclick="dev_del()">删除</a></li>
		   <li  class="listd" style="float:left;margin:2px"><a id="device_Export">导出</a></li>
		 </ul>
     </div>
   </div>
  
	<table class="table table-bordered deviceTblae" style="background:white">
	  <thead style="background-color:rgba(232,232,232,0.35);">
	 
		<tr>
		 <!--  <th style="text-align:center"><input type="checkbox"></input></th> -->
		  <th style="text-align:center"><input class="all_choose" type="checkbox"></input></th>
		  <th style="text-align:left">设备编号</th>
		  <th style="text-align:left">设备标识</th>
		  <th style="text-align:left">所属医院</th>
		  <th style="text-align:left">设备类型</th>
		  <th style="text-align:left">用户手机号</th>
		  <th style="text-align:right">姓名</th>
		  <th style="text-align:right">状态</th>
		 <!--  <td align="center" valign="middle">操作</td> -->
		</tr>
	  </thead>
	  <tbody class="data">
	  
	  </tbody>
	</table>

<ul class="pagination" id="pagelist" style="float:right;margin:0px">
</ul>
   </div>
 </div>
</div>
<!-- 修改--模态框 -->
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                <h4 class="modal-title" id="myModalLabel">修改设备数据</h4>
            </div>
            <div class="modal-body">
			    <form enctype="multipart/form-data" name="form1" method="post" action="<?php echo U('modify_device');?>" class="form-horizontal" role="form" >
				  <div class="form-group">
				  
					<label  for="" class="col-sm-2 control-label">设备编号</label>
					<div class="col-sm-10">
					  <input required="required" style="width:80%" name="device_num" type="text" class="form-control" id="device_num"><?php echo ($d["d_id"]); ?></input>
					</div>
					
				  </div>
				   <div class="form-group">
					<label  for="" class="col-sm-2 control-label">设备标识</label>
					<div class="col-sm-10">
					  <input required="required" style="width:80%" name="device_name"  type="text" class="form-control" id="device_name" >
					</div>
				  </div>
				   <div class="form-group">
					<label  for="" class="col-sm-2 control-label">所属医院</label>
					<div class="col-sm-10">
					  <input required="required" style="width:80%" name="hospital"  type="text" class="form-control" id="hospital">
					</div>
				  </div>
				   <div class="form-group">
					<label  for="" class="col-sm-2 control-label">设备类型</label>
					<div class="col-sm-10">
					   <select style="width:80%" name="device_style" id="device_style">
					    <option>体温计</option>
					  </select> 
					 </div>
				  </div>
				   <div class="form-group">
					<label  for="" class="col-sm-2 control-label">手机号</label>
					<div class="col-sm-10">
					  <input required="required" style="width:80%" name="number"  type="text" class="form-control" id="number" >
					</div>
				  </div>
				   <div class="form-group">
					<label  for="" class="col-sm-2 control-label">姓名</label>
					<div class="col-sm-10">
					  <input required="required" style="width:80%" name="name" type="text" class="form-control" id="name" >
					</div>
				  </div>
				   <div class="form-group">
					<label  for="" class="col-sm-2 control-label">状态</label>
					<div class="col-sm-10">
					   <select style="width:80%" name="device_status" id="device_status">
					    <option>未连接</option>
						<option>已连接</option>
						<option>设备故障</option>
					  </select>
					</div>
				  </div>
				  <input style="display:none" name="all_ID" id="all_ID"></input>
				  <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                    <button type="submit"  class="btn btn-primary">提交</button>
                  </div>
				</form>
			</div>
        </div><!-- /.modal-content -->
    </div><!-- /.modal -->
</div>

<!-- 增加--模态框 -->
<div class="modal fade" id="add_myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                <h4 class="modal-title" id="myModalLabel">增加设备数据</h4>
            </div>
            <div class="modal-body">
			    <form enctype="multipart/form-data" name="form1" method="post" action="<?php echo U('add_device');?>" class="form-horizontal" role="form" >
				  <div class="form-group">
				  
					<label  for="" class="col-sm-2 control-label">设备编号</label>
					<div class="col-sm-10">
					  <input required="required" style="width:80%" name="device_num1" type="text" class="form-control" id="device_num1"><?php echo ($d["d_id"]); ?></input>
					</div>
					
				  </div>
				   <div class="form-group">
					<label  for="" class="col-sm-2 control-label">设备标识</label>
					<div class="col-sm-10">
					  <input required="required" style="width:80%" name="device_name1" type="text" class="form-control" id="device_name1"><?php echo ($d["d_id"]); ?></input>
					 </div>
				  </div>
				 
				   <div class="form-group">
					<label  for="" class="col-sm-2 control-label">设备类型</label>
					<div class="col-sm-10">
					   <select style="width:80%" name="device_style1" id="device_style1">
					    <option>体温计</option>
					  </select> 
					 </div>
				  </div>
				  
				  <div class="form-group">
					<label  for="" class="col-sm-2 control-label">状态</label>
					<div class="col-sm-10">
					   <select style="width:80%" name="device_status1" id="device_status1">
					    <option>未连接</option>
						<option>已连接</option>
						<option>设备故障</option>
					  </select>
					</div>
				  </div>
				    <div class="form-group">
					<label  for="" class="col-sm-2 control-label">所属医院</label>
					<div class="col-sm-10">
					  <select style="width:80%" name="allow_hospital1" id="allow_hospital1">
 					    
					  </select>
					 </div>
				  </div>
				   <div class="form-group">
					<label  for="" class="col-sm-2 control-label">手机号</label>
					<div class="col-sm-10">
					   <select style="width:80%" name="user_phone1" id="user_phone1">
					    <option>未连接</option>
					  </select>
					 </div>
				  </div>
				   <div class="form-group">
					<label  for="" class="col-sm-2 control-label">姓名</label>
					<div class="col-sm-10">
					  <input readonly="readonly" required="required" style="width:80%" name="username1" type="text" class="form-control" id="username1" >
					</div>
				  </div>
				   
				  <input style="display:none" name="all_ID" id="all_ID"></input>
				  <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                    <button type="submit"  class="btn btn-primary">提交</button>
                  </div>
				  <input style="display:none" id="add_id_u" name="add_id_u"></input>
				  <input  style="display:none" id="add_id_h" name="add_id_h"></input>
				</form>
			</div>
        </div><!-- /.modal-content -->
    </div><!-- /.modal -->
</div>
 <script>
  $(function(){
    $(".search").click();
  });
 var flag = 0;
 $(".search").click(function(){
 debugger;
  	var cou = 0;
    $("select").each(function(){
	  if($(this).val() == "请选择"){
	    cou++;
	  }
	})
     if(cou == 5){
	   //alert("请选择查找条件");
	   flag = 1;
	 }else{
	   flag = 0;
	 }
   var bianhao1 = $("#bianhao").val();
   if(bianhao1 == ""){
     bianhao1 = "wu";
	 flag = 1;
   }else{
    flag = 0;
   }	 
   var sheng = $("#sheng").val();
   var qu = $("#qu").val();
   var yiyuan = $("#yiyuan").val();
   var bianhao = $("#bianhao").val();
   var leixing = $("#leixing").val();
   var sta = $("#static").val();
   $.ajax({
  	    url: '/javajy/index.php/Admin/Wenlian/equipment_search_Management',
  	    type: 'POST',
 	    dataType: 'JSON',//here
		data:{
		  sta1:flag,
		  sheng:sheng,
		  qu:qu,
		  yiyuan:yiyuan,
		  bianhao:bianhao,
		  leixing:leixing,
		  status:sta
		 },
 	      success: function(data){
		  debugger;
		  $("#count").html(data.length);
		   var html=''
		   if(data.length == 0){
				alert("没有找到数据、请重新查找");
			 }
		  var pagesize=10; 
	      var len;
	      var _len=data.length;
	      if(data.length<pagesize){
	            len=data.length;
	         }else{
	           len=pagesize;

	         }
			  for(var i =0; i <len; i++){
			    html+=
				'<tr>'
				  +'<td style="text-align:center"><input class="choose" name="roled" h_id="'+data[i]["h_id"]+'" u_id="'+data[i]["u_id"]+'" d_id="'+data[i]["d_id"]+'" type="checkbox"></input></td>'
				  +'<td style="text-align:left">'+data[i]["d_number"]+'</td>'
				  +'<td style="text-align:left">'+data[i]["d_name"]+'</td>'
				  +'<td style="text-align:left">'+data[i]["h_name"]+'</td>'
				  +'<td style="text-align:left">'+data[i]["d_style"]+'</td>'
				  +'<td style="text-align:left">'+data[i]["u_phonenum"]+'</td>'
				  +'<td style="text-align:right">'+data[i]["u_realname"]+'</td>'
				  +'<td style="text-align:right">'+data[i]["d_status"]+'</td>'
				  //+'<td width="120" align="center" valign="middle"><a class="audioEdit" href="<?php echo U('audioEdit','id='.$list['fID']);?>">修改</a> <a class="del" href="<?php echo U('audioDelete','id='.$list['fID']);?>" onClick="return confirm("确定要删除吗？")">删除</a></td>'
				+'</tr>'
			  }
			  $(".data").html(html);
   var  count=Math.ceil(_len/10);
      var pagehtml='';
      if(_len>10){
        $('#pagelist').empty();
         for(var i=1;i <= count;i++){

          pagehtml='';
          pagehtml +=
              '<li id='+i+'><a href="#">'+i+'</a></li>'
 
            $('#pagelist').append(pagehtml);

        }

    }
   $('#pagelist li').each(function(){

      $(this).click(function(){

               var id=$(this).attr('id');
               var startid=(id-1)*10;
               var endid=id*10;
               if(endid<_len){
                  endid=endid;

               }else{
                endid=_len;
               }
               $('.data').empty();
          var _html='';
        for(var i = startid; i <endid;i++){
         debugger;
          _html +=
				'<tr>'
				  +'<td style="text-align:center"><input class="choose" name="roled" h_id="'+data[i]["h_id"]+'" u_id="'+data[i]["u_id"]+'" d_id="'+data[i]["d_id"]+'" type="checkbox"></input></td>'
				  +'<td style="text-align:left">'+data[i]["d_number"]+'</td>'
				  +'<td style="text-align:left">'+data[i]["d_name"]+'</td>'
				  +'<td style="text-align:left">'+data[i]["h_name"]+'</td>'
				  +'<td style="text-align:left">'+data[i]["d_style"]+'</td>'
				  +'<td style="text-align:left">'+data[i]["u_phonenum"]+'</td>'
				  +'<td style="text-align:right">'+data[i]["u_realname"]+'</td>'
				  +'<td style="text-align:right">'+data[i]["d_status"]+'</td>'
				  //+'<td width="120" align="center" valign="middle"><a class="audioEdit" href="<?php echo U('audioEdit','id='.$list['fID']);?>">修改</a> <a class="del" href="<?php echo U('audioDelete','id='.$list['fID']);?>" onClick="return confirm("确定要删除吗？")">删除</a></td>'
				+'</tr>'
			  }
			  $(".data").html(_html);

           })

        })




			    //单选
			   $(".choose").click(function(){
				 var all_choose = $(".all_choose").is(':checked');
				 if(all_choose){
					$(".all_choose").prop('checked',false);
				 }
			   });
 	        }
  	  });
 });
   //全选
  $(".all_choose").click(function(){
     var flag = $(this).is(':checked');
	 if(flag){
	    $(".choose").each(function(){
		  $(this).prop('checked',true);
	    })
	 }else{
	    $(".choose").each(function(){
		  $(this).prop('checked',false);
	    })
	 }
  })
  
  
  //删除del
  function dev_del(){
    var len = $("input[type='checkbox']:checked").length;//修改数据的个数
	if(len == 0){
	   alert("请选择删除的设备");
	}else{
	  var d_arr = new Array();//存放设备id
	  $(".choose").each(function(){
        var f_this = $(this).is(':checked');		
        if(f_this){
			d_arr.push($(this).attr("d_id"));
	     }		
	   })
      var string = JSON.stringify(d_arr);//将数组转为json
	  $.ajax({
  	    url: '/javajy/index.php/Admin/Wenlian/del_device1',
  	    type: 'POST',
 	    dataType: 'JSON',//here
		data:{
		   str:string
		 },
 	     success: function(data){
		  alert(data);
		  location.reload(true);                                     
		 }
	   });
	}
  }
  //修改
  $("#modify").click(function(){
     //var d_arr = new Array();//存放设备id
	 //var u_arr = new Array();//存放用户id
	// var h_arr = new Array();//存放医院id
	 var len = $("input[type='checkbox']:checked").length;//修改数据的个数
	 if(len == 0){
	   alert("请选择修改的设备");
	   return false;
	 }else if(len!=1){
	   alert("每次只能修改一个设备数据");
	   return false;
	 }
	 var arr_d = new Array();//需要修改的所有数据ID
     $(".choose").each(function(){
        var f_this = $(this).is(':checked');		
        if(f_this){
		   arr_d.push($(this).attr("d_id"), $(this).attr("u_id"), $(this).attr("h_id"));
		  //d_arr.push($(this).attr("d_id"));
		  //u_arr.push($(this).attr("u_id"));
		 // h_arr.push($(this).attr("h_id"));
		}		
	 })
	  var string = JSON.stringify(arr_d);//将数组转为json
	  $.ajax({
  	    url: '/javajy/index.php/Admin/Wenlian/need_modify_device',
  	    type: 'POST',
 	    dataType: 'JSON',//here
		data:{
		   da:string
		 },
 	     success: function(data){ 		 	 
		   $("#device_num").val(data[0][0]["d_number"]);
		   $("#device_name").val(data[0][0]["d_name"]);
		   $("#hospital").val(data[2][0]["h_name"]);
		   $("#device_style").val(data[0][0]["d_style"]);
		   $("#number").val(data[1][0]["u_phonenum"]);
		   $("#name").val(data[1][0]["u_realname"]);
		   $("#device_status").val(data[0][0]["d_status"]);
		   $("#all_ID").val(data[0][0]["d_id"]+","+data[1][0]["u_id"]+","+data[2][0]["h_id"]);
		 }
	   });
  })
 //获取日期与时间
 function getNowFormatDate() {
    var date = new Date();
    var seperator1 = "-";
    var year = date.getFullYear();
    var month = date.getMonth() + 1;
    var strDate = date.getDate();
	var hours = date.getHours(); //获取当前小时数(0-23)
    var min =  date.getMinutes(); //获取当前分钟数(0-59)
    var second = date.getSeconds(); //获取当前秒数(0-59)
	
    if (month >= 1 && month <= 9) {
         month = "0" + month;
    }
    if (strDate >= 0 && strDate <= 9) {
        strDate = "0" + strDate;
    }
	if(hours >=0 && hours <= 9){
	   hours = "0" + hours;
	}
	if(min >=0 && min <= 9){
	   min = "0" + min;
	}
	if(second >=0 && second <= 9){
	   second = "0" + second;
	}
    var currentdate = year + seperator1 + month + seperator1 + strDate +" "+hours +"时" + min+"分" + second+"秒";
    return currentdate;
 } 
 //导出exce
 var exportData = document.getElementById("device_Export");
 exportData.onclick = function(){
    //$(".deviceTblae").tableExport({ type: 'excel', separator: ';', escape: 'false' });
	var fName = $("#fileName").html();
	var currentTime =  getNowFormatDate();
	fName = fName+'_'+currentTime;
	$(".deviceTblae").tableExport({ type: 'excel', separator: ',', escape: 'false',fileName:fName });
 }
 </script>

</body>
</html>